<?php
class Car
{
    const WHEELS = 4; //汽车都是4个轮子
    var $seats; //座位
    var $doors; //门
    var $engine; //发动机
    var $brand; //品牌

     function __constructor($brand, $seats = 5, $doors = 4, $engine = 1) { 
        $this->$seats = $seats; 
        $this->$doors = $doors; 
        $this->$engine = $engine; 
        $this->$brand = $brand; 
        
	}

    function getSeats()
    {
        return $this->seats;
    }

    function setSeats($seats): void
    {
        $this->seats = $seats;
    }

    function getDoors()
    {
        return $this->doors;
    }

    function setDoors($doors): void
    {
        $this->doors = $doors;
    }

    function getEngine()
    {
        return $this->engine;
    }

    function setEngine($engine): void
    {
        $this->engine = $engine;
    }

    function getBrand()
    {
        return $this->brand;
    }

    function setBrand($brand): void
    {
        $this->brand = $brand;
    }

    /**
     * 开车
     * @return void
     */
    public function drive()
    {
        echo "1.启动引擎..." . '<br/>';
        echo "2.挂D档..." . '<br/>';
        echo "3.放下手刹..." . '<br/>';
        echo "4.踩油门，出发..." . '<br/>';
        printf("5.%s汽车已出发\n", $this->brand);
    }

    /**
     * 熄火
     * @return void
     */
    public function close()
    {
        echo "1.踩刹车..." . '<br/>';
        echo "2.挂P档..." . '<br/>';
        echo "3.拉起手刹..." . '<br/>';
        echo "4.关闭引擎..." . '<br/>';
        printf("5.%s汽车已熄火\n", $this->brand);

    }

    
}

class Benz extends Car
{
    private $customProp = "自定义属性";

    public function __construct($seats = 5, $doors = 4, $engine = 1)
    {
        $this->brand = "奔驰";
        parent::__constructor($this->brand, $seats, $doors, $engine);
    }

    private function customMethod()
    {
        echo "Call custom prop \$customProp: " . $this->customProp . '<br/>';
        echo "This is a custom method in Benz Class" . '<br/>';
    }

    public function drive()
    {
        echo $this->getBrand() . '汽车的启动流程：<br/>';
        parent::drive();
    }
}

class TestCarDrive
{
    public function testDrive(Car $car)
    {
        $car->drive();
    }

    public function testBenzDrive(Benz $benz)
    {
        $benz->drive();
    }
}
$car = new Car();
var_dump(Car::WHEELS);

$car->setBrand("奔驰");
var_dump($car->getBrand());
var_dump($car->getSeats());
var_dump($car->getDoors());
var_dump($car->getEngine());


$car->drive();
$car->close();

echo '<br/>Benz<br/>';
$benz = new Benz();
$benz->drive();
// $benz->customMethod();

$method = new ReflectionMethod(Benz::class, 'customMethod');
$method->setAccessible(true);

$benz = new Benz();
$method->invoke($benz);

echo '<br/>类型转化<br/>';
//初始化类对象
$bmw = new Car('宝马');
$benz = new Benz();
$test = new TestCarDrive();

//测试子类转父类
$test->testDrive($benz);
//测试父类转子类
$test->testBenzDrive($bmw);